JBoss Community Archive (Read Only)

RHQ 4.7

Coding Standards

Java

Formatting

Until all code is formatted according to these conventions, please do separate commits for code formatting changes and code content changes.

Follow the Oracle/Sun Java Code Conventions with the following additions:

  • Do not use * imports:

  • Use the following import order:

java
<blank line>
javax
<blank line>
<all other imports>
<blank line>
com
<blank line>
org
<blank line>
org.jboss
<blank line>
net.hyperic
<blank line>
org.jboss.on
<blank line>
org.rhq

Formatting with Eclipse

Configure Eclipse to use these two settings files in RHQ git:

  • .settings/org.eclipse.jdt.core.prefs

  • .settings/org.eclipse.jdt.ui.prefs

Formatting with IntelliJ IDEA

Download the Eclipse Code Formatter IntelliJ plugin and point it at the Eclipse settings files specified above. In addition, be sure to set the import order manual configuration to java;javax;com;org;org.jboss;org.rhq 

Style

General

  • Use the following file header, where xx is the year the file was created, and yy is the year it was last modified:

    /*
     * RHQ Management Platform
     * Copyright 20xx-20yy, Red Hat Middleware LLC, and individual contributors
     * as indicated by the @author tags. See the copyright.txt file in the
     * distribution for a full listing of individual contributors.
     *
     * This program is free software; you can redistribute it and/or modify
     * it under the terms of the GNU General Public License as published by
     * the Free Software Foundation version 2 of the License.
     *
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     * GNU General Public License for more details.
     *
     * You should have received a copy of the GNU General Public License
     * along with this program; if not, write to the Free Software
     * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     */
  • Don't use section comments like "// Constructors".

  • Abbreviation is evil (in most cases)... do not hurt readability to save three characters. Someone two years from now isn't going to know what the hell an SRN is. Don't abbreviate packages, classes or members. "em" is not an appropriate member name for an injected "entityManager". Even abbreviations that seem obvious cause problems because of inconsistent usage. If you choose to shorten configuration to config, others may choose not to. Only use abbreviations that are already the global standard. (e.g. URL is fine)

  • Use injection in EJB3. Don't use messy manual JNDI lookups where you don't need to.

Javadoc

  • Use a header like below for class and interface javadoc. (Don't use email addresses in the author tag and don't use @version $Revision$)

    /**
     * Description goes here
     *
     * @author John Mazzitelli
     * @author Ian Springer
     */

    If no author tag is specified for a class, Joseph Marques is most likely the author.

  • Avoid /** @see */ javadoc comments.

EJB

  • Naming

    EJB3 Stateless Session Beans
      <BusinessName>Bean: Implementation class
      <BusinessName>Local: Local interface
      <BusinessName>Remote: Remote interface
    
    BusinessNames:
      <PrimaryEntity>Manager: For code that deals primarily with one entity
      <UseCaseGroup>Boss: For code that is use case oriented
    
    Examples:
      DiscoveryBossBean, DiscoveryBossRemote, DiscoveryBossLocal (Deals with the use case of inventory discovery)
      ResourceManagerBean, ResourceManagerLocal (Deals in the storage of and access to Resource and its dependent entities)
  • Use constants for the names of all NamedQueries. This helps us three ways... a) avoid typing the wrong name for a query and not knowing until runtime, b) be able to "Find Usages" to see everyone using a query and c) Autocomplete to find the available queries.

    @NamedQueries({
       /* ResourceManagerBean queries */
       @NamedQuery(name = QUERY_FIND_BY_PARENT_AND_INVENTORY_STATUS,
                   query = "SELECT res ...
    ...
    
    public static final String QUERY_FIND_BY_PARENT_AND_INVENTORY_STATUS = "Resource.findByParentAndInventoryStatus";

XML / HTML / JSON

  • Use 2-space indents for child elements.

JBoss.org Content Archive (Read Only), exported from JBoss Community Documentation Editor at 2020-03-12 14:13:16 UTC, last content change 2012-07-17 21:05:38 UTC.